Terrain = function (scene) 
{
	this.load = function()
	{
		this.loadTerrain('big2s.bin', function (data) {
	        // console.log(data);
			var geometry = new THREE.PlaneGeometry(512, 512, 511, 511);
			geometry.computeFaceNormals();
			geometry.computeVertexNormals();

			for (var i = 0, l = geometry.vertices.length; i < l; i++) {
				geometry.vertices[i].z = (data[i] / 65535 * 3200 - 200) / 193.4;
			}
			var material = new THREE.MeshPhongMaterial({
				map: THREE.ImageUtils.loadTexture('shanxi.png')
			});
			var plane = new THREE.Mesh(geometry, material);
			// plane.castShadow = true;
			// plane.receiveShadow = true;
			plane.rotation.x = -Math.PI / 2;
			plane.rotation.z = -Math.PI / 2;
			plane.position.y = -0.31;
			plane.scale.set(1.46/512.0 * 91/111, 1.46/512.0, 1.46/512.0);
			scene.add(plane);
		});
	}
	
	this.loadTerrain = function(file, callback)
	{
        var req = new XMLHttpRequest();
        req.responseType = 'arraybuffer';
        req.open('GET', file, true);
        req.onload = function(evt) {
            if (req.response) {
                callback(new Uint16Array(req.response));
            }
        };
        req.send(null);
    }
};
